// 获取用户名输入后提示是否合规
// 获取对象
const username = document.querySelector("input[name=username]");
const password = document.querySelector("input[name=password]");
// 获取确认密码对象
const respassword = document.querySelector("input[name=respassword]");

const btn = document.querySelector('button')
// 注册事件，输入即触发
username.oninput = function () {
  const val = this.value.trim();
  // console.log(val)
  //定义前端检验
  // 只能编写字母与数字
  if (/^[A-z0-9]{6,8}$/.test(val)) {
    this.nextElementSibling.innerHTML = "输入的用户名可用";
    this.nextElementSibling.style.color = "green";
  } else {
    this.nextElementSibling.innerHTML = "输入的用户名不可用";
    this.nextElementSibling.style.color = "red";
  }
};
// 注册事件，输入即触发
password.oninput = function () {
  const val = this.value.trim();
  // console.log(val)
  //定义前端检验
  // 只能编写字母与数字
  if (/^[A-z0-9]{6,8}$/.test(val)) {
    this.nextElementSibling.innerHTML = "输入密码可用";
    this.nextElementSibling.style.color = "green";
  } else {
    this.nextElementSibling.innerHTML = "输入的密码不可用";
    this.nextElementSibling.style.color = "red";
  }
};
if (respassword) {
  respassword.oninput = function () {
    const respasswordval = this.value.trim();
    const psw = password.value.trim();
    if (respasswordval === psw) {
      this.nextElementSibling.innerText = "与密码一致";
      this.nextElementSibling.style.color = "green";
      btn.disabled = false;
    } else {
      // 提示用户不通过
      this.nextElementSibling.innerText = "密码不一致";
      this.nextElementSibling.style.color = "red";
    }
  }
}else {
    btn.disabled = false;
}

    
    btn.onclick = function (e) {
        let spans=document.querySelector('span')
        spans = Array.from(spans);
        const result = spans.some(
            (item) => {
                return item.style.color !=='green'
            }
        )
        if(result) e.preventDefault()

    }


    



    



